import {CHANGE_INPUT,ADD_ITEM,DELETE_ITEM} from './action-type'
const defaultState = {
    inputValue:'请添加待办事项',
    list:['早上八点，需需求沟通', '早上九点，吃零食', '早上10点，摸鱼开始']
}
const reducer= (state = defaultState, action) => {
    if(action.type===CHANGE_INPUT){
        let newState=JSON.parse(JSON.stringify(state))
        newState.inputValue=action.value
        return newState
    }
    if(action.type===ADD_ITEM){
        let newState=JSON.parse(JSON.stringify(state))
        newState.list.push(newState.inputValue)
        newState.inputValue=''
        return newState
    }
    if(action.type===DELETE_ITEM){
        let newState=JSON.parse(JSON.stringify(state))
        newState.list.splice(action.index,1)
        return newState
    }
	return state
}
export default reducer